//
//  BaseTableViewController.m
//  王雷Sinoweibo
//
//  Created by wanglei on 16/10/20.
//  Copyright © 2016年 wanglei. All rights reserved.
//

#import "BaseTableViewController.h"
#import "VisitorLoginView.h"
#import "OAuthViewController.h"

#import "UserAccount.h"
#import "AccountViewModel.h"
#import "BarMoreButtonController.h"



@interface BaseTableViewController ()<VisitorLoginViewDelegate,UITableViewDelegate,UITableViewDataSource>

@end

@implementation BaseTableViewController

- (void)userWillLogin;{
    
    NSLog(@"userWillLogin");
    [self presentToOauther];
}

- (void)userWillRegister;{
    
    BarMoreButtonController *buttonController = [[BarMoreButtonController alloc]init];
    
    [self.navigationController pushViewController:buttonController animated:YES];
    //http://www.jianshu.com/p/d39f7d22db6c#fn_link_2 全屏侧滑的简介
    
    NSLog(@"userWillRegister");
}

//纯代码创建控制器的方法入口
-(void)loadView{
    
//   access_token用户是否成功登陆的标志,如果是nil,表示用户未成功登陆

    self.isUserLogin = [AccountViewModel sharedAccountModel].userLogin;
    
    if (self.isUserLogin) {
        
        [super loadView];
    }else{
        VisitorLoginView *loginView1 = [[VisitorLoginView alloc]init];
        
#pragma mark :注意此处的把loginView赋值给self.loginView很有必要
        self.loginView = loginView1;
        
//        注意此处代理对象的设置,self在此处是代理者,loginView1是委托者
        loginView1.delegate = self;

//      self.loginview将来要调用setupInfoWith'''那个方法,这样才能将视图转换过来
        self.view = _loginView;
    }
    
   }


-(void)viewDidAppear:(BOOL)animated{
    UIBarButtonItem *leftbarbuttonitem = [[UIBarButtonItem alloc]initWithTitle:@"登录" style:UIBarButtonItemStylePlain target:self action:@selector(userWillLogin)];
    
    [self.navigationItem setLeftBarButtonItem:leftbarbuttonitem animated:YES];
    
    UIBarButtonItem *rightbarbuttonitem = [[UIBarButtonItem alloc]initWithTitle:@"注册" style:UIBarButtonItemStylePlain target:self action:@selector(userWillRegister)];
    
    [self.navigationItem setRightBarButtonItem:rightbarbuttonitem animated:YES];
    
  
    
}

- (void)presentToOauther{
    OAuthViewController *controller = [[OAuthViewController alloc]init];
    UINavigationController *navcontroller = [[UINavigationController alloc]initWithRootViewController:controller];
    [self presentViewController:navcontroller animated:YES completion:nil];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
}


@end
